Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

Given the following partial class, add the necessary constructor function so that both declarations within main() are valid. class samp { int a; public: //add constructor functions int get_a() {...

Given the following partial class, add the necessary constructor function so that both declarations within main() are valid.

class samp {
int a;
public:
//add constructor functions
int get_a() { return a;}
};
int main()
{
samp ob(88); //init ob's a to 88
samp obarray[10]; //nonitialized 10-element array
// ...
}

Answers


Davis

#include
using namespace std;
class samp {
int a;
public:
samp() { a = 0;}
samp(int n) { a = n;}
int get_a() { return a;}
};
int main()
{
samp ob(88);
samp obarray[10];
// ...
}
Githiari answered the question on May 31, 2018 at 18:03

Answer Attachments

Exams With Marking Schemes

Related Questions